{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torchvision.datasets import CIFAR10\n",
    "import os\n",
    "\n",
    "train_set = CIFAR10(\"./data\", train=True, download=True)\n",
    "print(\"CIFAR10 train dataset:\", len(train_set))\n",
    "\n",
    "images = []\n",
    "labels = []\n",
    "for img, label in train_set:\n",
    "    images.append(img)\n",
    "    labels.append(label)\n",
    "\n",
    "labels = torch.tensor(labels)\n",
    "for i in range(10):\n",
    "    assert (labels == i).sum() == 5000\n",
    "\n",
    "output_dir = \"./data/cifar10-pngs/\"\n",
    "for i, pil in enumerate(images):\n",
    "    pil.save(os.path.join(output_dir, \"{:05d}.png\".format(i)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.5 ('gan')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "da18559f301618e6e9fab00c6d05e566e4e63dfec8a595f965f0c783b8f75048"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
